home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / as.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  13.5 KB  |  479 lines

  1. /* as.h - global header file
  2.    Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #define GAS 1
  21. /*
  22.  * I think this stuff is largely out of date.  xoxorich.
  23.  *
  24.  * CAPITALISED names are #defined.
  25.  * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
  26.  * "lowercaseT" is a typedef of "lowercase" objects.
  27.  * "lowercaseP" is type "pointer to object of type 'lowercase'".
  28.  * "lowercaseS" is typedef struct ... lowercaseS.
  29.  *
  30.  * #define DEBUG to enable all the "know" assertion tests.
  31.  * #define SUSPECT when debugging hash code.
  32.  * #define COMMON as "extern" for all modules except one, where you #define
  33.  *    COMMON as "".
  34.  * If TEST is #defined, then we are testing a module: #define COMMON as "".
  35.  */
  36.  
  37. /* These #defines are for parameters of entire assembler. */
  38.  
  39. #define DEBUG            /* temporary */
  40. /* These #includes are for type definitions etc. */
  41.  
  42. #include <stdio.h>
  43. #ifdef DEBUG
  44. #undef NDEBUG
  45. #endif
  46. #include <assert.h>
  47.  
  48. #include <ansidecl.h>
  49. #ifdef BFD_ASSEMBLER
  50. #include <bfd.h>
  51. #endif
  52. #include "host.h"
  53. #include "flonum.h"
  54.  
  55. #ifndef __LINE__
  56. #define __LINE__ "unknown"
  57. #endif /* __LINE__ */
  58.  
  59. #ifndef __FILE__
  60. #define __FILE__ "unknown"
  61. #endif /* __FILE__ */
  62.  
  63. #ifndef __STDC__
  64. #ifndef const
  65. #define const
  66. #endif
  67. #ifndef volatile
  68. #define volatile
  69. #endif
  70. #endif /* ! __STDC__ */
  71.  
  72. #define obstack_chunk_alloc xmalloc
  73. #define obstack_chunk_free xfree
  74.  
  75. #define xfree free
  76.  
  77. #define BAD_CASE(value) \
  78. { \
  79.       as_fatal("Case value %d unexpected at line %d of file \"%s\"\n", \
  80.            value, __LINE__, __FILE__); \
  81.        }
  82.  
  83.  
  84. /* These are assembler-wide concepts */
  85.  
  86. #ifdef BFD_ASSEMBLER
  87. extern bfd *stdoutput;
  88. #endif
  89.  
  90. #ifndef COMMON
  91. #ifdef TEST
  92. #define COMMON            /* declare our COMMONs storage here. */
  93. #else
  94. #define COMMON extern        /* our commons live elswhere */
  95. #endif
  96. #endif
  97. /* COMMON now defined */
  98.  
  99. #ifdef DEBUG
  100. #ifndef know
  101. #define know(p) assert(p)    /* Verify our assumptions! */
  102. #endif /* not yet defined */
  103. #else
  104. #define know(p)            /* know() checks are no-op.ed */
  105. #endif
  106.  
  107. #if defined (BROKEN_ASSERT) && !defined (NDEBUG)
  108. /* Used on machines where the "assert" macro is buggy.  (For example, on the
  109.    RS/6000, Reiser-cpp substitution is done to put the condition into a
  110.    string, so if the condition contains a string, parse errors result.)  If
  111.    the condition fails, just drop core file.  */
  112. #undef assert
  113. #define assert(p) ((p) ? 0 : (abort (), 0))
  114. #endif
  115.  
  116. /* input_scrub.c */
  117.  
  118. /*
  119.  * Supplies sanitised buffers to read.c.
  120.  * Also understands printing line-number part of error messages.
  121.  */
  122.  
  123.  
  124. /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
  125.  
  126. #ifndef BFD_ASSEMBLER
  127. /*
  128.  * This table describes the use of segments as EXPRESSION types.
  129.  *
  130.  *    X_seg    X_add_symbol  X_subtract_symbol    X_add_number
  131.  * SEG_ABSENT                        no (legal) expression
  132.  * SEG_PASS1                        no (defined) "
  133.  * SEG_BIG                    *    > 32 bits const.
  134.  * SEG_ABSOLUTE                         0
  135.  * SEG_DATA        *                 0
  136.  * SEG_TEXT        *            0
  137.  * SEG_BSS        *            0
  138.  * SEG_UNKNOWN        *            0
  139.  * SEG_DIFFERENCE    0        *    0
  140.  * SEG_REGISTER                    *
  141.  *
  142.  * The blank fields MUST be 0, and are nugatory.
  143.  * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
  144.  *
  145.  * SEG_BIG: X_add_number is < 0 if the result is in
  146.  *    generic_floating_point_number.  The value is -'c' where c is the
  147.  *    character that introduced the constant.  e.g. "0f6.9" will have  -'f'
  148.  *    as a X_add_number value.
  149.  *    X_add_number > 0 is a count of how many littlenums it took to
  150.  *    represent a bignum.
  151.  * SEG_DIFFERENCE:
  152.  * If segments of both symbols are known, they are the same segment.
  153.  * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
  154.  */
  155.  
  156.  
  157. #ifdef MANY_SEGMENTS
  158. #include "bfd.h"
  159. #define N_SEGMENTS 10
  160. #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
  161. #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
  162. #define SEG_TEXT SEG_E0
  163. #define SEG_DATA SEG_E1
  164. #define SEG_BSS SEG_E2
  165. #else
  166. #define N_SEGMENTS 3
  167. #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
  168. #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
  169. #endif
  170.  
  171. typedef enum _segT
  172.   {
  173.     SEG_ABSOLUTE = 0,
  174.     SEG_LIST,
  175.     SEG_UNKNOWN,
  176.     SEG_ABSENT,            /* Mythical Segment (absent): NO expression seen. */
  177.     SEG_PASS1,            /* Mythical Segment: Need another pass. */
  178.     SEG_GOOF,            /* Only happens if AS has a logic error. */
  179.     /* Invented so we don't crash printing */
  180.     /* error message involving weird segment. */
  181.     SEG_BIG,            /* Bigger than 32 bits constant. */
  182.     SEG_DIFFERENCE,        /* Mythical Segment: absolute difference. */
  183.     SEG_DEBUG,            /* Debug segment */
  184.     SEG_NTV,            /* Transfert vector preload segment */
  185.     SEG_PTV,            /* Transfert vector postload segment */
  186.     SEG_REGISTER,        /* Mythical: a register-valued expression */
  187.   } segT;
  188.  
  189. #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
  190. #else
  191. typedef asection *segT;
  192. #define SEG_NORMAL(SEG)        ((SEG) != absolute_section    \
  193.                  && (SEG) != undefined_section    \
  194.                  && (SEG) != big_section    \
  195.                  && (SEG) != reg_section    \
  196.                  && (SEG) != pass1_section    \
  197.                  && (SEG) != diff_section    \
  198.                  && (SEG) != absent_section)
  199. #endif
  200. typedef int subsegT;
  201.  
  202. /* What subseg we are accreting now? */
  203. COMMON subsegT now_subseg;
  204.  
  205. /* Segment our instructions emit to. */
  206. COMMON segT now_seg;
  207.  
  208. #ifdef BFD_ASSEMBLER
  209. #define segment_name(SEG)    bfd_get_section_name (stdoutput, SEG)
  210. #else
  211. extern char *const seg_name[];
  212. #define segment_name(SEG)    seg_name[(int) (SEG)]
  213. #endif
  214.  
  215. #ifndef BFD_ASSEMBLER
  216. extern int section_alignment[];
  217. #endif
  218.  
  219. #ifdef BFD_ASSEMBLER
  220. extern segT big_section, reg_section, pass1_section;
  221. extern segT diff_section, absent_section;
  222. /* Shouldn't these be eliminated someday?  */
  223. extern segT text_section, data_section, bss_section;
  224. #define absolute_section    (&bfd_abs_section)
  225. #define undefined_section    (&bfd_und_section)
  226. #else
  227. #define big_section        SEG_BIG
  228. #define reg_section        SEG_REGISTER
  229. #define pass1_section        SEG_PASS1
  230. #define diff_section        SEG_DIFFERENCE
  231. #define absent_section        SEG_ABSENT
  232. #define text_section        SEG_TEXT
  233. #define data_section        SEG_DATA
  234. #define bss_section        SEG_BSS
  235. #define absolute_section    SEG_ABSOLUTE
  236. #define undefined_section    SEG_UNKNOWN
  237. #endif
  238.  
  239. /* relax() */
  240.  
  241. typedef enum _relax_state
  242.   {
  243.     /* Variable chars to be repeated fr_offset times.
  244.        Fr_symbol unused. Used with fr_offset == 0 for a
  245.        constant length frag. */
  246.     rs_fill = 1,
  247.  
  248.     /* Align: Fr_offset: power of 2. 1 variable char: fill character. */
  249.     rs_align,
  250.  
  251.     /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
  252.        character. */
  253.     rs_org,
  254.  
  255.     rs_machine_dependent,
  256.  
  257. #ifndef WORKING_DOT_WORD
  258.     /* JF: gunpoint */
  259.     rs_broken_word,
  260. #endif
  261.   } relax_stateT;
  262.  
  263. /* typedef unsigned char relax_substateT; */
  264. /* JF this is more likely to leave the end of a struct frag on an align
  265.    boundry.  Be very careful with this.  */
  266. typedef unsigned long relax_substateT;
  267.  
  268. /* Enough bits for address, but still an integer type.
  269.    Could be a problem, cross-assembling for 64-bit machines.  */
  270. typedef unsigned long relax_addressT;
  271.  
  272.  
  273. /* frags.c */
  274.  
  275. /*
  276.  * A code fragment (frag) is some known number of chars, followed by some
  277.  * unknown number of chars. Typically the unknown number of chars is an
  278.  * instruction address whose size is yet unknown. We always know the greatest
  279.  * possible size the unknown number of chars may become, and reserve that
  280.  * much room at the end of the frag.
  281.  * Once created, frags do not change address during assembly.
  282.  * We chain the frags in (a) forward-linked list(s). The object-file address
  283.  * of the 1st char of a frag is generally not known until after relax().
  284.  * Many things at assembly time describe an address by {object-file-address
  285.  * of a particular frag}+offset.
  286.  
  287.  BUG: it may be smarter to have a single pointer off to various different
  288.  notes for different frag kinds. See how code pans
  289.  */
  290. struct frag
  291. {
  292.   /* Object file address. */
  293.   unsigned long fr_address;
  294.   /* Chain forward; ascending address order.  Rooted in frch_root. */
  295.   struct frag *fr_next;
  296.  
  297.   /* (Fixed) number of chars we know we have.  May be 0. */
  298.   long fr_fix;
  299.   /* (Variable) number of chars after above.  May be 0. */
  300.   long fr_var;
  301.   /* For variable-length tail. */
  302.   struct symbol *fr_symbol;
  303.   /* For variable-length tail. */
  304.   long fr_offset;
  305.   /* Points to opcode low addr byte, for relaxation.  */
  306.   char *fr_opcode;
  307.  
  308. #ifndef NO_LISTING
  309.   struct list_info_struct *line;
  310. #endif
  311.  
  312.   /* What state is my tail in? */
  313.   relax_stateT fr_type;
  314.   relax_substateT fr_subtype;
  315.  
  316.   /* These are needed only on the NS32K machines */
  317.   char fr_pcrel_adjust;
  318.   char fr_bsr;
  319.  
  320.   /* Chars begin here.
  321.      One day we will compile fr_literal[0]. */
  322.   char fr_literal[1];
  323. };
  324.  
  325. #define SIZEOF_STRUCT_FRAG \
  326. ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
  327. /* We want to say fr_literal[0] above. */
  328.  
  329. typedef struct frag fragS;
  330.  
  331. /* Current frag we are building.  This frag is incomplete.  It is, however,
  332.    included in frchain_now.  The fr_fix field is bogus; instead, use:
  333.    obstack_next_free(&frags)-frag_now->fr_literal.  */
  334. COMMON fragS *frag_now;
  335. #define frag_now_fix() (obstack_next_free (&frags) - frag_now->fr_literal)
  336.  
  337. /* For foreign-segment symbol fixups. */
  338. COMMON fragS zero_address_frag;
  339. /* For local common (N_BSS segment) fixups. */
  340. COMMON fragS bss_address_frag;
  341.  
  342. /* main program "as.c" (command arguments etc) */
  343.  
  344. /* ['x'] TRUE if "-x" seen. */
  345. COMMON char flagseen[128];
  346. COMMON unsigned char flag_readonly_data_in_text;
  347. COMMON unsigned char flag_suppress_warnings;
  348. COMMON unsigned char flag_always_generate_output;
  349.  
  350. /* name of emitted object file */
  351. COMMON char *out_file_name;
  352.  
  353. /* TRUE if we need a second pass. */
  354. COMMON int need_pass_2;
  355.  
  356. /* TRUE if we should do no relaxing, and
  357.    leave lots of padding.  */
  358. COMMON int linkrelax;
  359.  
  360. struct _pseudo_type
  361.   {
  362.     /* assembler mnemonic, lower case, no '.' */
  363.     char *poc_name;
  364.     /* Do the work */
  365.     void (*poc_handler) ();
  366.     /* Value to pass to handler */
  367.     int poc_val;
  368.   };
  369.  
  370. typedef struct _pseudo_type pseudo_typeS;
  371.  
  372. #ifdef BFD_ASSEMBLER_xxx
  373. struct lineno_struct
  374.   {
  375.     alent line;
  376.     fragS *frag;
  377.     struct lineno_struct *next;
  378.   };
  379. typedef struct lineno_struct lineno;
  380. #endif
  381.  
  382. #if defined (__STDC__) && !defined(NO_STDARG)
  383.  
  384. #if __GNUC__ >= 2
  385. /* for use with -Wformat */
  386. #define PRINTF_LIKE(FCN)    void FCN (const char *Format, ...) \
  387.                     __attribute__ ((format (printf, 1, 2)))
  388. #else /* ANSI C with stdarg, but not GNU C */
  389. #define PRINTF_LIKE(FCN)    void FCN (const char *Format, ...)
  390. #endif
  391. #else /* not ANSI C, or not stdarg */
  392. #define PRINTF_LIKE(FCN)    void FCN ()
  393. #endif
  394.  
  395. PRINTF_LIKE (as_bad);
  396. PRINTF_LIKE (as_fatal);
  397. PRINTF_LIKE (as_tsktsk);
  398. PRINTF_LIKE (as_warn);
  399.  
  400. int had_errors PARAMS ((void));
  401. int had_warnings PARAMS ((void));
  402.  
  403. char *app_push PARAMS ((void));
  404. char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
  405. char *input_scrub_include_file PARAMS ((char *filename, char *position));
  406. char *input_scrub_new_file PARAMS ((char *filename));
  407. char *input_scrub_next_buffer PARAMS ((char **bufp));
  408. char *strstr PARAMS ((const char *s, const char *wanted));
  409. char *xmalloc PARAMS ((long size));
  410. char *xrealloc PARAMS ((char *ptr, long n));
  411. int do_scrub_next_char PARAMS ((int (*get) (), void (*unget) ()));
  412. int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
  413.               long exponent_bits));
  414. int had_err PARAMS ((void));
  415. int had_errors PARAMS ((void));
  416. int had_warnings PARAMS ((void));
  417. int ignore_input PARAMS ((void));
  418. int scrub_from_file PARAMS ((void));
  419. int scrub_from_file PARAMS ((void));
  420. int scrub_from_string PARAMS ((void));
  421. int seen_at_least_1_file PARAMS ((void));
  422. void app_pop PARAMS ((char *arg));
  423. void as_howmuch PARAMS ((FILE * stream));
  424. void as_perror PARAMS ((char *gripe, char *filename));
  425. void as_where PARAMS ((void));
  426. void bump_line_counters PARAMS ((void));
  427. void do_scrub_begin PARAMS ((void));
  428. void input_scrub_begin PARAMS ((void));
  429. void input_scrub_close PARAMS ((void));
  430. void input_scrub_end PARAMS ((void));
  431. void int_to_gen PARAMS ((long x));
  432. void new_logical_line PARAMS ((char *fname, int line_number));
  433. void scrub_to_file PARAMS ((int ch));
  434. void scrub_to_string PARAMS ((int ch));
  435. void subsegs_begin PARAMS ((void));
  436. void subseg_change PARAMS ((segT seg, int subseg));
  437. #ifdef BFD_ASSEMBLER
  438. segT subseg_new PARAMS ((char *name, subsegT subseg));
  439. void subseg_set PARAMS ((segT seg, subsegT subseg));
  440. #else
  441. void subseg_new PARAMS ((segT seg, subsegT subseg));
  442. #endif
  443.  
  444. /* this one starts the chain of target dependant headers */
  445. #include "targ-env.h"
  446.  
  447. /* these define types needed by the interfaces */
  448. #include "struc-symbol.h"
  449.  
  450. #include "write.h"
  451. #include "expr.h"
  452. #include "frags.h"
  453. #include "hash.h"
  454. #include "read.h"
  455. #include "symbols.h"
  456.  
  457. #include "tc.h"
  458. #include "obj.h"
  459.  
  460. #include "listing.h"
  461.  
  462. #ifdef BFD_ASSEMBLER
  463. /* Someday perhaps this will be selectable at run-time.  */
  464. #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
  465. #define OUTPUT_FLAVOR bfd_target_aout_flavour
  466. #endif
  467. #ifdef OBJ_COFF
  468. #define OUTPUT_FLAVOR bfd_target_coff_flavour
  469. #endif
  470. #ifdef OBJ_ECOFF
  471. #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
  472. #endif
  473. #ifdef OBJ_ELF
  474. #define OUTPUT_FLAVOR bfd_target_elf_flavour
  475. #endif
  476. #endif /* BFD_ASSEMBLER */
  477.  
  478. /* end of as.h */
  479.